<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The MongoBinData class</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongoregex.tostring.html">MongoRegex::__toString</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongobindata.construct.html">MongoBinData::__construct</a></div>
 <div class="up"><a href="mongo.types.html">Types</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="class.mongobindata" class="reference">

 <h1 class="title">The MongoBinData class</h1>
 

 <div class="partintro"><p class="verinfo">(PECL mongo &gt;= 0.8.1)</p>


  <div class="section" id="mongobindata.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    An object that can be used to store or retrieve binary data from the database.
   </p>
   <p class="para">
    The maximum size of a single object that can be inserted into the database
    is 16MB. For data that is larger than this (movies, music, Henry Kissinger&#039;s
    autobiography), use <a href="class.mongogridfs.html" class="classname">MongoGridFS</a>. For data that is
    smaller than 16MB, you may find it easier to embed it within the document
    using <strong class="classname">MongoBinData</strong>.
   </p>
   <p class="para">
    For example, to embed an image in a document, one could write:
   </p>
   <div class="example" id="mongobindata.intro-example">
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$profile&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"username"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"foobity"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"pic"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoBinData</span><span style="color: #007700">(</span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">"gravatar.jpg"</span><span style="color: #007700">))<br />);<br /><br /></span><span style="color: #0000BB">$users</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">save</span><span style="color: #007700">(</span><span style="color: #0000BB">$profile</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
   <p class="para">
    This class contains a <var class="varname"><var class="varname">type</var></var> field, which currently gives 
    no additional functionality in the driver or the database.  There are five 
    predefined types (which are the class constants listed below), and the user 
    can create their own (at the risk of the BSON spec catching up with them). 
    By default, the PHP driver always uses type 2: a byte array.
   </p>
  </div>


  <div class="section" id="mongobindata.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">
     <span class="ooclass">
      <strong class="classname">MongoBinData</strong>
     </span>
     {</div>

    
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 常量 */</div>
    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongobindata.html#mongobindata.constants.func"><var class="varname">FUNC</var></a></var>
     <span class="initializer"> = 1</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongobindata.html#mongobindata.constants.bytearray"><var class="varname">BYTE_ARRAY</var></a></var>
     <span class="initializer"> = 2</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongobindata.html#mongobindata.constants.uuid"><var class="varname">UUID</var></a></var>
     <span class="initializer"> = 3</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongobindata.html#mongobindata.constants.md5"><var class="varname">MD5</var></a></var>
     <span class="initializer"> = 5</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongobindata.html#mongobindata.constants.custom"><var class="varname">CUSTOM</var></a></var>
     <span class="initializer"> = 128</span>
    ;</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Fields */</div>
    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="type">string</span>
      <var class="varname">$<var class="varname">bin</var></var>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="type">int</span>
      <var class="varname">$<var class="varname">type</var></var>
     <span class="initializer"> = 2</span>
    ;</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="mongobindata.construct.html" class="methodname">__construct</a></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$type</code><span class="initializer"> = 2</span></span>
  ] )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">string</span><span class="methodname"><a href="mongobindata.tostring.html" class="methodname">__toString</a></span>
    ( <span class="methodparam">void</span>
   )</div>

   }</div>


  </div>


  <div class="section">
   <h2 class="title">预定义常量</h2>
   <div class="section" id="mongobindata.constants.types">
    <h2 class="title">Binary Data Types</h2>
    <dl>

     
      <dt id="mongobindata.constants.func"><strong><code>MongoBinData::FUNC</code></strong></dt>

      <dt>
<strong><code>0x01</code></strong></dt>

      <dd>

       <span class="simpara">
        Function.
       </span>
      </dd>

     
     
      <dt id="mongobindata.constants.bytearray"><strong><code>MongoBinData::BYTE_ARRAY</code></strong></dt>

      <dt>
<strong><code>0x02</code></strong></dt>

      <dd>

       <span class="simpara">
        Array of bytes.
       </span>
      </dd>

     
     
      <dt id="mongobindata.constants.uuid"><strong><code>MongoBinData::UUID</code></strong></dt>

      <dt>
<strong><code>0x03</code></strong></dt>

      <dd>

       <span class="simpara">
        Universally unique identifier.
       </span>
      </dd>

     
     
      <dt id="mongobindata.constants.md5"><strong><code>MongoBinData::MD5</code></strong></dt>

      <dt>
<strong><code>0x05</code></strong></dt>

      <dd>

       <span class="simpara">
        MD5.
       </span>
      </dd>

     
     
      <dt id="mongobindata.constants.custom"><strong><code>MongoBinData::CUSTOM</code></strong></dt>

      <dt>
<strong><code>0x80</code></strong></dt>

      <dd>

       <span class="simpara">
        User-defined type.
       </span>
      </dd>

     
    </dl>

   </div>
  </div>


 </div>

 



















<h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="mongobindata.construct.html">MongoBinData::__construct</a> — 创建一个新的二进制数据对象</li><li><a href="mongobindata.tostring.html">MongoBinData::__toString</a> — 二进制数据对象的字符串表达形式。</li></ul>
</div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongoregex.tostring.html">MongoRegex::__toString</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongobindata.construct.html">MongoBinData::__construct</a></div>
 <div class="up"><a href="mongo.types.html">Types</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
